package cn.yuanqiao.archive.storeRoom.service.impl;

import cn.yuanqiao.archive.appManager.domain.DataScopeBase;
import cn.yuanqiao.archive.storeRoom.domain.Boxspec;
import cn.yuanqiao.archive.storeRoom.mapper.BoxspecMapper;
import cn.yuanqiao.archive.storeRoom.service.IBoxspecService;
import cn.yuanqiao.common.exception.ServiceException;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.SnowflakeIdGenerator;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 档案盒规格Service业务层处理
 * 
 * @author xy
 * @date 2023-06-19
 */
@Service
public class BoxspecServiceImpl implements IBoxspecService
{
    @Autowired
    private BoxspecMapper boxspecMapper;


    /**
     * 查询档案盒规格
     * 
     * @param specId 档案盒规格主键
     * @return 档案盒规格
     */
    @Override
    public Boxspec selectBoxspecBySpecId(Long specId)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
        }else{
            return boxspecMapper.selectBoxspecBySpecId(specId,tenantCode.toUpperCase());
        }
    }

    /**
     * 查询档案盒规格列表
     * 
     * @param boxspec 档案盒规格
     * @return 档案盒规格
     */
    @Override
    public List<Boxspec> selectBoxspecList(Boxspec boxspec)
    {

        return boxspecMapper.selectBoxspecList(new DataScopeBase(),boxspec);
    }

    /**
     * 新增档案盒规格
     * 
     * @param boxspec 档案盒规格
     * @return 结果
     */
    @Override
    public int insertBoxspec(Boxspec boxspec)
    {
        Long specId=SnowflakeIdGenerator.generateId();
        boxspec.setSpecId(specId);
        boxspec.setCreateTime(DateUtils.getNowDate());
        boxspec.setCreator(SecurityUtils.getUserId());
        boxspec.setSpecAcount(boxspec.getSpecCount());
        boxspec.setIsDel(0);
        return boxspecMapper.insertBoxspec(boxspec);

    }

    /**
     * 修改档案盒规格
     * 
     * @param boxspec 档案盒规格
     * @return 结果
     */
    @Override
    public int updateBoxspec(Boxspec boxspec)
    {
        boxspec.setLastupdater(SecurityUtils.getUserId());
        boxspec.setLastupdateTime(DateUtils.getNowDate());
         return boxspecMapper.updateBoxspec(boxspec);


    }

    /**
     * 批量删除档案盒规格
     * 
     * @param specIds 需要删除的档案盒规格主键
     * @return 结果
     */
    @Override
    public int deleteBoxspecBySpecIds(Long[] specIds)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
        }else{
            return boxspecMapper.deleteBoxspecBySpecIds(specIds,tenantCode.toUpperCase());

        }
    }

    /**
     * 删除档案盒规格信息
     * 
     * @param specId 档案盒规格主键
     * @return 结果
     */
    @Override
    public int deleteBoxspecBySpecId(Long specId)
    {
        String tenantCode = SecurityUtils.getTenantCode();
        if(StringUtils.isEmpty(tenantCode)) {
            throw new ServiceException("TenantCode is null");
        }else{
            return boxspecMapper.deleteBoxspecBySpecId(specId,tenantCode.toUpperCase());

        }
    }
}
